# -*- coding:utf-8 -*-
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.wait import WebDriverWait
import time

def login_qichacha(url):
    browser = webdriver.Chrome()
    try:
        browser.get(url)
        login = browser.find_element_by_xpath('//li[a/@href="/user_login"]')
        if login:
            login.click()
            input = browser.find_element_by_id("normalLogin")
            input.click()
            inname = browser.find_element_by_id("nameNormal")
            inname.send_keys("15215663921")
            inpass = browser.find_element_by_id("pwdNormal")
            inpass.send_keys("a14879")
            wait = WebDriverWait(browser, 300, 2)
            wait.until(EC.presence_of_element_located((By.CSS_SELECTOR, "[class='nc_iconfont btn_ok']")))
            enter = browser.find_element_by_xpath("//button[@type='submit']")
            enter.click()
            print("cookies",browser.get_cookies())
            cook = browser.get_cookies()
            for i in cook:
                browser.add_cookie(i)
            browser.get(url)
            # for i in cook:
            #     browser.add_cookie(i)
            print(browser.page_source)
            time.sleep(60)
    except Exception as e:
        print("登陆失败",str(e))

if __name__ == '__main__':
    login_qichacha("https://www.qichacha.com//firm_dc32419276ad5fe5ebcf5a5059c95987.html")